package admin.forms;

import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;

import entities.Page;

public class PageForm {
	public TreeMap checkValid(HttpServletRequest request, Page page) {
		TreeMap form = new TreeMap();
		TreeMap check = new TreeMap();
		
		String title = (String) request.getParameter("title");
		String content = (String) request.getParameter("content");
		
		if (title == null || title.isEmpty()) {
			check.put("title", "Title is not empty");
			page.setTitle("");
		} else {
			page.setTitle(title);
		}
		
		if (content == null || content.isEmpty()) {
			check.put("content", "Content is not empty");
			page.setContent("");
		} else {
			page.setContent(content);
		}
		
		form.put("checkValid", check);
		form.put("page", page);
		
		return form;
	}
}
